package com.fr.base.core.antlr;

public class ANTLRHashString
{
  private String s;
  private char[] buf;
  private int len;
  private CharScanner lexer;
  private static final int prime = 151;

  public ANTLRHashString(char[] paramArrayOfChar, int paramInt, CharScanner paramCharScanner)
  {
    this.lexer = paramCharScanner;
    setBuffer(paramArrayOfChar, paramInt);
  }

  public ANTLRHashString(CharScanner paramCharScanner)
  {
    this.lexer = paramCharScanner;
  }

  public ANTLRHashString(String paramString, CharScanner paramCharScanner)
  {
    this.lexer = paramCharScanner;
    setString(paramString);
  }

  private final char charAt(int paramInt)
  {
    return ((this.s != null) ? this.s.charAt(paramInt) : this.buf[paramInt]);
  }

  public boolean equals(Object paramObject)
  {
    ANTLRHashString localANTLRHashString;
    if ((!(paramObject instanceof ANTLRHashString)) && (!(paramObject instanceof String)))
      return false;
    if (paramObject instanceof String)
      localANTLRHashString = new ANTLRHashString((String)paramObject, this.lexer);
    else
      localANTLRHashString = (ANTLRHashString)paramObject;
    int i = length();
    if (localANTLRHashString.length() != i)
      return false;
    if (this.lexer.getCaseSensitiveLiterals())
    {
      j = 0;
      while (true)
      {
        if (j >= i)
          break label150;
        if (charAt(j) != localANTLRHashString.charAt(j))
          return false;
        ++j;
      }
    }
    for (int j = 0; j < i; ++j)
      if (this.lexer.toLower(charAt(j)) != this.lexer.toLower(localANTLRHashString.charAt(j)))
        return false;
    label150: return true;
  }

  public int hashCode()
  {
    int i = 0;
    int j = length();
    if (this.lexer.getCaseSensitiveLiterals())
    {
      k = 0;
      while (true)
      {
        if (k >= j)
          break label74;
        i = i * 151 + charAt(k);
        ++k;
      }
    }
    for (int k = 0; k < j; ++k)
      i = i * 151 + this.lexer.toLower(charAt(k));
    label74: return i;
  }

  private final int length()
  {
    return ((this.s != null) ? this.s.length() : this.len);
  }

  public void setBuffer(char[] paramArrayOfChar, int paramInt)
  {
    this.buf = paramArrayOfChar;
    this.len = paramInt;
    this.s = null;
  }

  public void setString(String paramString)
  {
    this.s = paramString;
    this.buf = null;
  }
}